package com.myapp.api.mapper;

import com.myapp.api.entity.Major;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface MajorMapper {
    @Delete({
        "delete from major",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into major (id, Mid, ",
        "Did, Mname, Minfo, ",
        "CreateTime, UpdateTime)",
            "values (#{id,jdbcType=INTEGER}, #{mid,jdbcType=VARCHAR}, ",
            "#{did,jdbcType=VARCHAR}, #{mname,jdbcType=VARCHAR}, #{minfo,jdbcType=VARCHAR}, ",
        "#{createtime,jdbcType=TIMESTAMP}, #{updatetime,jdbcType=TIMESTAMP})"
    })
    int insert(Major record);

    @InsertProvider(type=MajorSqlProvider.class, method="insertSelective")
    int insertSelective(Major record);

    @Select({
        "select",
        "id, Mid, Did, Mname, Minfo, CreateTime, UpdateTime",
        "from major",
            "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Mid", property = "mid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "Did", property = "did", jdbcType = JdbcType.VARCHAR),
        @Result(column="Mname", property="mname", jdbcType=JdbcType.VARCHAR),
        @Result(column="Minfo", property="minfo", jdbcType=JdbcType.VARCHAR),
        @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="UpdateTime", property="updatetime", jdbcType=JdbcType.TIMESTAMP)
    })
    Major selectByPrimaryKey(Integer id);

    @UpdateProvider(type=MajorSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Major record);

    @Update({
        "update major",
            "set Mid = #{mid,jdbcType=VARCHAR},",
            "Did = #{did,jdbcType=VARCHAR},",
          "Mname = #{mname,jdbcType=VARCHAR},",
          "Minfo = #{minfo,jdbcType=VARCHAR},",
          "CreateTime = #{createtime,jdbcType=TIMESTAMP},",
          "UpdateTime = #{updatetime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Major record);

    @Select({
            "select",
            "id, Mid, Did, Mname, Minfo, CreateTime, UpdateTime",
            "from major"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Mid", property = "mid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "Did", property = "did", jdbcType = JdbcType.VARCHAR),
            @Result(column="Mname", property="mname", jdbcType=JdbcType.VARCHAR),
            @Result(column="Minfo", property="minfo", jdbcType=JdbcType.VARCHAR),
            @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="UpdateTime", property="updatetime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<Major> getMajors();

    @Select({
            "select",
            "id, Mid, Did, Mname, Minfo, CreateTime, UpdateTime",
            "from major",
            "where Mid = #{mid,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Mid", property = "mid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "Did", property = "did", jdbcType = JdbcType.VARCHAR),
            @Result(column="Mname", property="mname", jdbcType=JdbcType.VARCHAR),
            @Result(column="Minfo", property="minfo", jdbcType=JdbcType.VARCHAR),
            @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="UpdateTime", property="updatetime", jdbcType=JdbcType.TIMESTAMP)
    })
    Major getMajorByMid(String mid);

    @Select({
            "select count(*)",
            "id, Mid, Did, Mname, Minfo, CreateTime, UpdateTime",
            "from major",
            "where Mid = #{mid,jdbcType=VARCHAR}"
    })
    Integer getMajorByOneMid(String mid);

    @Select({
            "select",
            "id, Mid, Did, Mname, Minfo, CreateTime, UpdateTime",
            "from major",
            "where Mname like concat('%',#{mname,jdbcType=VARCHAR},'%')"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Mid", property = "mid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "Did", property = "did", jdbcType = JdbcType.VARCHAR),
            @Result(column="Mname", property="mname", jdbcType=JdbcType.VARCHAR),
            @Result(column="Minfo", property="minfo", jdbcType=JdbcType.VARCHAR),
            @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="UpdateTime", property="updatetime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<Major> getMajorByMname(String mname);
}